package com.oauth.twitter.server.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.oauth.service.global.ApplicationGlobalServiceAdapter;
import com.oauth.service.global.beans.OAuthAccessToken;
import com.oauth.service.global.beans.OAuthRequestToken;

@Service
@Qualifier("twitterGlobalService")
public class TwitterGlobalService extends ApplicationGlobalServiceAdapter {

	@Autowired
	private TwitterService twitterService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.oauth.service.application.global.ApplicationGlobalServiceAdapter#
	 * updateStatus(java.lang.Long, java.lang.String)
	 */
	@Override
	public boolean updateStatus(Long pMemberId, String pStatusText) {
		// TODO Auto-generated method stub
		// mOrkutOAuthService.
		try {
			twitterService.updateTweet(pStatusText, pMemberId);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	/**
	 * @return
	 * @throws Exception
	 * @see com.oauth.twitter.server.service.TwitterService#getAccessToken()
	 */
	public OAuthAccessToken getAccessToken(OAuthRequestToken requestToken) {
		try {
			return twitterService.getAccessToken(requestToken);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @return
	 * @throws Exception
	 * @see com.oauth.twitter.server.service.TwitterService#getRequestToken()
	 */
	@Override
	public OAuthRequestToken getRequestToken() {
		try {
			return twitterService.getRequestToken();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @param twitterService
	 *            the twitterOAuthService to set
	 */
	public void setTwitterService(TwitterService twitterService) {
		this.twitterService = twitterService;
	}

}
